package com.loginlib.table;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.loginlib.R;
import com.loginlib.di.component.DaggerTableActivityComponent;
import com.loginlib.di.component.TableActivityComponent;
import com.loginlib.di.module.TableModule;
import com.loginlib.panel.TablePanel;
import com.loginlib.presenters.TablePresenter;
import com.loginlib.table.adapter.TablePageViewAdapter;
import com.wanhe.base.BaseActivity;
import com.wanhe.base.model.entity.TableResultEntity;

import javax.inject.Inject;


public class TableActivity extends BaseActivity implements TablePanel {
    //
    @Inject
    TablePresenter mPresenter;
    ViewPager vpTablePage;
    private TablePageViewAdapter mAdapter;
    private TableActivityComponent tableActivityComponent;

    @Override
    protected void initComponent(Bundle savedInstanceState) {
        setContentView(R.layout.activity_table);
        vpTablePage = (ViewPager) findViewById(R.id.vp_table_page);
        initInject();
//        AppContext.getInstance().addTempActivity(this);
//        ActivityStackMananger.getInstance().addActivityStack(this);
        mPresenter.setTablePanel(this);
        mPresenter.getTotalTableInfo(1);
        mAdapter = new TablePageViewAdapter(this);
        vpTablePage.setAdapter(mAdapter);
    }

    public void initInject() {
        tableActivityComponent = DaggerTableActivityComponent.builder().tableModule(new TableModule()).build();
        tableActivityComponent.inject(this);
    }

    @Override
    public void getTablesSuccess(TableResultEntity resultEntity) {
        dismissDialog();
        if (resultEntity != null) {
            mAdapter.setCount(resultEntity.PageTotal);
        }
    }

    @Override
    public void getTablesFail(String msg) {

    }

    @Override
    public void onLoading() {
        showDialog();
    }

    @Override
    public void disLoading() {
        dismissDialog();
    }
}
